﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OtherDevice
{
    public partial class Form_Sino四色温 : Form_ControlBase
    {
        public Form_Sino四色温()
        {
            InitializeComponent();
        }
        LightCtrlBase lightCtrlBase;
        public override void FlushToDlg(object devicebase)
        {
            try
            {
                if (devicebase == null)
                    return;
                this.lightCtrlBase = devicebase as LightCtrlBase;
                this.Dock = DockStyle.Fill;
                this.Show();
            }
            catch (Exception)
            {

            }
        }

        private void btn_打开_Click(object sender, EventArgs e)
        {
            try
            {
                int ch = comboBox1.SelectedIndex;
                if (ch == -1)
                {
                    MessageBox.Show("请选择通道");
                    return;
                }
                if (int.TryParse(txt_亮度值.Text, out int value))
                {
                    if (value > 4000)
                    {
                        value = 4000;
                    }
                    else if (value < 0)
                    {
                        value = 0;
                    }
                    lightCtrlBase.Set(ch, value);
                }
                else
                {
                    MessageBox.Show("请输入0-4000亮度值");
                    return;
                }
            }
            catch (Exception ex)
            {
                UIMessageBox.ShowError($"设置Chart光源(四色温)亮度出错:{ex.Message}+{ex.StackTrace}");
            }
        }

        private void btn_关闭_Click(object sender, EventArgs e)
        {
            try
            {
                int ch = comboBox1.SelectedIndex;
                if (ch == -1)
                {
                    MessageBox.Show("请选择通道");
                    return;
                }

                lightCtrlBase.Set(ch, 0);
            }
            catch (Exception ex)
            {
                UIMessageBox.ShowError($"关闭Chart光源(四色温)亮度出错:{ex.Message}+{ex.StackTrace}");
            }
        }
    }
}
